var express = require('express');
var request = require('request');
var bodyParser = require('body-parser');
var fs = require('fs');
var url = require("url");
var querystring = require("querystring");
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));

//POST请求地址
app.post('/http/post',function(req,res){
	console.log(req.body);
	var option = JSON.parse(req.body.option);
	console.log(option);
	request.get(option,function(error, response, body){
		console.log(error);
		res.send(body);
	});
});

//下载文件
app.get('/http/download',function(req,res){
	var objectUrl = url.parse(req.url);
	var objectQuery = querystring.parse(objectUrl.query);
	var fileUrl = objectQuery.url;
	console.log(fileUrl);
	request(fileUrl).pipe(res);	
})

function GUID()
{
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
			var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
			return v.toString(16);
			});
}

app.listen(9089);

